<%@ page import="com.qf.pojo.Student" %>
<%@ page import="java.util.List" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
    <script src="/js/jquery-3.4.1.min.js"></script>
    <script type="text/javascript">
        function findByCondition(){
            var s_name = $("#s_name").val();
            var s_address = $("#s_address").val();
            window.location.href = "${pageContext.request.contextPath}/studentList?s_name="+s_name+"&s_address="+s_address;
        }


        function deleteStu(stuId){

            $.get("/deleteStudent2",{"id":stuId},function (data){
                // alert(data.code)
                // alert(data.msg)

                if(data.msg=="true"){
                    alert("删除成功");
                    //重新加载列表数据
                    window.location.href = "${pageContext.request.contextPath}/studentList";
                }

            },"json");

        }
    </script>
</head>
<body>

   <input type="text" placeholder="请输入学员姓名" id="s_name" value="${s_name}"  >
   <input type="text" placeholder="请输入家庭地址" id="s_address" value="${s_address}"  >

   <button onclick="findByCondition()" >查询</button>

   <a href="${pageContext.request.contextPath}/studentAdd.jsp">添加</a>
<table>
    <tr>
        <th>
            编号
        </th>
        <th>
            姓名
        </th>
        <th>
            姓别
        </th>
        <th>
            生日
        </th>
        <th>
            电话
        </th>
        <th>
            住址
        </th>
        <th>
            爱好
        </th>
        <th>
            操作
        </th>
    </tr>

    <c:forEach items="${page.pageData}" var="stu">
        <tr>
            <td>
                ${stu.id}
            </td>
            <td>
                ${stu.name}
            </td>
            <td>
                ${stu.sex}
            </td>
            <td>
                ${stu.birthday}
            </td>
            <td>
                ${stu.phone}
            </td>
            <td>
                ${stu.address}
            </td>
            <td>
                ${stu.hobby}
            </td>
            <td>
                <a href="${pageContext.request.contextPath}/studentUpdate?id=${stu.id}">修改</a>
                <a href="${pageContext.request.contextPath}/deleteStudent?id=${stu.id}">删除传统方式</a>
                <a href="javascript:deleteStu(${stu.id})">删除ajax方式</a>

            </td>
        </tr>
    </c:forEach>

</table>

<HR>
<div>
    当前第 [${page.pageNum}]页
    <c:if test="${page.pageNum>1}">
        <a href="${pageContext.request.contextPath}/studentList?pageNum=${page.pageNum-1}">上一页</a>
    </c:if>

    <c:forEach var="num" begin="${page.startPageNum}" end="${page.endPageNum}">
        <c:choose>
            <c:when test="${num==page.pageNum}">
                [${num}]

            </c:when>
            <c:otherwise>
                <a href="${pageContext.request.contextPath}/studentList?pageNum=${num}">[${num}]</a>
            </c:otherwise>
        </c:choose>

    </c:forEach>

    <c:if test="${page.pageNum<page.totalPageNum}">
        <a href="${pageContext.request.contextPath}/studentList?pageNum=${page.pageNum+1}">下一页</a>
    </c:if>
    共${page.totalPageNum}页
</div>
</body>
</html>
